const classNames = require('classnames')
const _ = require('../utils')

_.create('card', {
  properties: {
    variant: String,
    media: String,
    mediaPosition: {
      type: String,
      value: 'top',
    },
    actions: Array,
  },

  computed: {
    classes(data) {
      const { classPrefix, variant, mediaPosition } = data
      const classes = classNames(classPrefix, {
        [`${classPrefix}-${variant}`]: variant,
        [`${classPrefix}-media-${mediaPosition}`]:
          ['top', 'left', 'right'].indexOf(mediaPosition) === -1 ? 'top' : mediaPosition,
      })

      return classes
    },
  },

  methods: {
    onActionsTap(e) {
      if (e.detail.index === undefined) return
      this.triggerEvent('actions', e.detail)
    },
  },
})
